import { RegularExpression } from '@/common/constVariable';
import { useDescriptionsType } from '@/components/DescriptionsType';
import { Select } from 'antd';
import { useEffect } from 'react';

const getInvestUpdateConfig = ({ pageType, record, assetInvestForm, mapLoading, assetValueType }) => {
  useEffect(() => {
    /** 回填表单 */
    if (pageType === 'view' || pageType === 'edit') {
      assetInvestForm?.setFieldsValue({
        ...record.assetjson,
      });
    }
  }, [record]);

  const [investConfig, investMethods] = useDescriptionsType({
    labelWidth: 190,
    basicForm: assetInvestForm,
    name: 'accept-assetInvestForm',
    schemas: [
      {
        key: 'accept-null',
        title: '',
        fieldChildren: [],
      },
      {
        key: 'accept-info',
        title: '材料信息',
        fieldChildren: [
          {
            field: `ledgerAccount`,
            label: `单位会计科目`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          {
            field: `investUnitCreditCode`,
            label: `被投资单位统一社会信用代码`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          {
            field: `investUnitName`,
            label: `被投资单位名称`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
          {
            field: `bondMoney`,
            label: `债券票面金额`,
            component: 'InputNumber',
            placeholder: '请输入',
            disabled: pageType === 'view',
            min: 1,
            // contentAfter: '份',
            pattern: RegularExpression?.twoFloatNumber,
            patternMsg: '请输入整数或保留两位小数',
          },
          {
            field: `beginInvestDate`,
            label: `初始投资日期`,
            component: 'DatePicker',
            disabled: pageType === 'view',
            format: 'YYYY-MM-DD',
            placeholder: '请选择',
          },
          {
            field: `bondRate`,
            label: `债券票面利率`,
            component: 'InputNumber',
            placeholder: '请输入',
            disabled: pageType === 'view',
            min: 0,
            contentAfter: '%',
            pattern: RegularExpression?.twoFloatNumber,
            patternMsg: '请输入整数或保留两位小数',
          },
          {
            field: `shareholdRatio`,
            label: `持股比例`,
            component: 'InputNumber',
            placeholder: '请输入',
            disabled: pageType === 'view',
            min: 0,
            contentAfter: '%',
            pattern: RegularExpression?.twoFloatNumber,
            patternMsg: '请输入整数或保留两位小数',
          },
          {
            field: `investOrgType`,
            label: `被投资单位组织形式`,
            component: 'Render',
            disabled: pageType === 'view',
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '个人组织',
                      value: 0,
                    },
                    {
                      label: '集体组织',
                      value: 1,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `investIsMarket`,
            label: `被投资单位是否上市`,
            component: 'Render',
            disabled: pageType === 'view',
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '否',
                      value: 0,
                    },
                    {
                      label: '是',
                      value: 1,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `investStockCode`,
            label: `被投资单位股票代码`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          {
            field: `investOperation`,
            label: `被投资单位经营情况`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          {
            field: `valueType`,
            label: `价值类型`,
            disabled: pageType === 'view',
            component: 'Render',
            required: true,
            render: (text) => {
              return (
                <Select
                  loading={mapLoading}
                  options={assetValueType}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                  fieldNames={{
                    label: 'name',
                    value: 'id',
                  }}
                />
              );
            },
          },
          {
            field: `paperMoney`,
            label: `账面价值`,
            component: 'InputNumber',
            placeholder: '请输入',
            disabled: pageType === 'view',
            min: 0,
            contentAfter: '元',
            required: true,
            pattern: RegularExpression?.twoFloatNumber,
            patternMsg: '请输入',
          },
          {
            field: `entryState`,
            label: `财务入账状态`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '未入账',
                      value: 0,
                    },
                    {
                      label: '已入账',
                      value: 1,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `financialOfficer`,
            label: `财务负责人`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
          },
          {
            field: `denseState`,
            label: `定密状态`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '未定密',
                      value: 0,
                    },
                    {
                      label: '已定密',
                      value: 1,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `denseDate`,
            label: `定密时间`,
            component: 'DatePicker',
            disabled: pageType === 'view',
            format: 'YYYY-MM-DD',
            placeholder: '请选择',
            required: true,
          },
          {
            field: `longTime`,
            label: `是否长期`,
            component: 'Render',
            disabled: pageType === 'view',
            required: true,
            render: (text) => {
              return (
                <Select
                  options={[
                    {
                      label: '是',
                      value: 1,
                    },
                    {
                      label: '否',
                      value: 0,
                    },
                  ]}
                  disabled={pageType === 'view'}
                  placeholder="请选择"
                />
              );
            },
          },
          {
            field: `secrecyTerm`,
            label: `保密期限`,
            disabled: pageType === 'view',
            component: 'Input',
            placeholder: '请输入',
            required: true,
          },
        ],
      },
    ],
  });

  return {
    investConfig,
    investMethods,
  };
};

export { getInvestUpdateConfig };
